<template>
  <div>
    <el-dialog
      title="配置"
      :visible.sync="isShowModel"
      :before-close="handleClose"
      width="600px"
    >
      <el-form ref="form" :model="param" :rules="rules" label-suffix="：" label-width="120px">
        <el-form-item label="字典CODE" prop="code">
          <el-input v-model="param.code" disabled />
        </el-form-item>
        <el-form-item label="字典值" prop="val">
          <el-input v-model="param.val" />
        </el-form-item>
        <el-form-item label="字典值说明" prop="description">
          <el-input v-model="param.description" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button :loading="subLoading" type="primary" @click="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { DictEditPost } from '@/api'
import { rules } from './config'
export default {
  data() {
    return {
      param: {},
      subLoading: false,
      isShowModel: false,
      rules
    }
  },
  methods: {
    onSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.subLoading = true
          DictEditPost({ param: { ...this.param }}).then(res => {
            this.$store.dispatch('user/initDictAction')
            this.handleClose()
            this.$emit('success')
          })
        }
      })
    },
    handleClose() {
      this.isShowModel = false
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
